package com.sxpi.lock;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author: 董伟豪
 * @Date: 2022/11/6 17:51
 */
@Slf4j
public class LockThread implements Runnable{

    // 存钱和取钱的金额
    private int count;

    public LockThread(int count){
        this.count = count;
    }

    @Override
    public void run() {
        // 线程干的事情
        for (int i = 0; i < 10; i++) {
            // 共享同一个实例
            synchronized (LockThread.class){
                // 通过传进来的金额，（可正，可负）执行叠加操作
                SystemContants.amount = SystemContants.amount + count;
                // 输出每次操作完成账户的余额
                log.info("此时账户余额是：{}",SystemContants.amount);
            }

        }
    }
}
